import 'package:flutter/material.dart';
import 'package:smart_shop/page/cart/index.dart';
import 'package:smart_shop/page/category/index.dart';
import 'package:smart_shop/page/home/index.dart';
import 'package:smart_shop/page/mine/index.dart';

class TabbarPage extends StatefulWidget {
  const TabbarPage({super.key});

  @override
 createState() => _TabbarPageState();
}

class _TabbarPageState extends State<TabbarPage> {
  List tabList = [
    {
      'label': '首页',
      'activeIcon': 'assets/tabbar/home-active.png',
      'icon': 'assets/tabbar/home.png',
    },
    {
      'label': '分类',
      'activeIcon': 'assets/tabbar/cate-active.png',
      'icon': 'assets/tabbar/cate.png',
    },
    {
      'label': '购物车',
      'activeIcon': 'assets/tabbar/cart-active.png',
      'icon': 'assets/tabbar/cart.png',
    },
    {
      'label': '我的',
      'activeIcon': 'assets/tabbar/user-active.png',
      'icon': 'assets/tabbar/user.png',
    }
  ];
  
  int currentIndex = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: currentIndex,
        children: const [
          HomePage(),
          CategoryPage(),
          CartPage(),
          MinePage(),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: currentIndex,
        onTap: (index) {
          setState(() {
            currentIndex = index;
          });
        },
        type: BottomNavigationBarType.fixed,
        selectedItemColor: Colors.red,
        unselectedItemColor: Colors.grey,
        items: tabList.map((item) {
          return BottomNavigationBarItem(
            label: item['label'],
            icon: Image.asset(item['icon'], width: 30),
            activeIcon: Image.asset(item['activeIcon'], width: 30),
          );
        }).toList(),
      ),
    );
  }
}